package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@Api(tags = "护理等级接口")
@RequestMapping("/nursingLevel")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<NursingLevelVo> listAll() {
       List< NursingLevelVo> nursingLevelVo =  nursingLevelService.listAll();
        return ResponseResult.success(nursingLevelVo);

    }

    @PostMapping("/insert")
    @ApiOperation( "添加护理等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingProjectDto) {
        nursingLevelService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级")
    public ResponseResult<NursingLevelVo> PageNursing(Integer pageNum,Integer pageSize,String name,  Integer status) {
        PageResponse<NursingLevelVo> pageInfo = nursingLevelService.PageNursing( pageNum, pageSize, name, status);
        return success(pageInfo);
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }
    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingProjectDto) {
        nursingLevelService.update(nursingProjectDto);
        return success();
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(@PathVariable Long id) {
        nursingLevelService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理项目ID", required = true) @PathVariable Long id,
            @ApiParam(value = "护理项目状态", required = true) @PathVariable Integer status) {
        nursingLevelService.modifyState(id, status);
        return success();
    }
}
